package com.elcom.player.overlay;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

public class overlay {
	private static TextView mInfo;
	
    private static final int SURFACE_BEST_FIT = 0;
    private static final int SURFACE_FIT_HORIZONTAL = 1;
    private static final int SURFACE_FIT_VERTICAL = 2;
    private static final int SURFACE_FILL = 3;
    private static final int SURFACE_16_9 = 4;
    private static final int SURFACE_4_3 = 5;
    private static final int SURFACE_ORIGINAL = 6;
    private static final int OVERLAY_TIMEOUT = 4000;
    private static final int OVERLAY_INFINITE = 3600000;
    private static final int FADE_OUT = 1;
    private static final int SHOW_PROGRESS = 2;
    private static final int SURFACE_SIZE = 3;
    private static final int FADE_OUT_INFO = 4;
    private int mCurrentSize = SURFACE_BEST_FIT;
    
    private static Context mContext;
    private Activity mActivity;
	public overlay(TextView mInfo, Context mContext,Activity mActivity){
		this.mInfo = mInfo;
		this.mContext = mContext;
		this.mActivity = mActivity;
	}	
	
	public void clickListener(int mCurrentSize){
        switch (mCurrentSize) {
            case SURFACE_BEST_FIT:
                showInfo("Best Fit", 1000);
                break;
            case SURFACE_FIT_HORIZONTAL:
                showInfo("fit horizontal", 1000);
                break;
            case SURFACE_FIT_VERTICAL:
                showInfo("fit vertical", 1000);
                break;
            case SURFACE_FILL:
                showInfo("FullScreen", 1000);
                break;
            case SURFACE_16_9:
                showInfo("16:9", 1000);
                break;
            case SURFACE_4_3:
                showInfo("4:3", 1000);
                break;
            case SURFACE_ORIGINAL:
                showInfo("original", 1000);
                break;
        }
        //showOverlay();
    
	}
	public void showInfo(String text) {
        mInfo.setVisibility(View.VISIBLE);
        mInfo.setText(text);
        mVideoHandler.removeMessages(FADE_OUT_INFO);
    }
    /**
     * Show text in the info view for "duration" milliseconds
     * @param text: string
     * @param duration: ms
     */
    public void showInfo(String text, int duration) {
        mInfo.setVisibility(View.VISIBLE);
        mInfo.setText(text);
        mVideoHandler.removeMessages(FADE_OUT_INFO);
        mVideoHandler.sendEmptyMessageDelayed(FADE_OUT_INFO, duration);
    }
    /**
     * hide the info view with "delay" milliseconds delay
     * @param delay
     */
    public void hideInfo(int delay) {
        mVideoHandler.sendEmptyMessageDelayed(FADE_OUT_INFO, delay);
    }

    /**
     * hide the info view
     */
    public void hideInfo() {
        hideInfo(0);
    }
	private static void fadeOutInfo() {
        if (mInfo.getVisibility() == View.VISIBLE)
            mInfo.startAnimation(AnimationUtils.loadAnimation(
                    mContext, android.R.anim.fade_out));
        mInfo.setVisibility(View.INVISIBLE);
    }
    private Handler mVideoHandler = new VideoPlayerHandler();
    private  class VideoPlayerHandler extends Handler{

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case FADE_OUT_INFO:
                	fadeOutInfo();
                    break;
            }
        }
    };
}
